﻿// Copyright 2006 - Ricardo Stuven (rstuven@gmail.com)
//
// This file is part of MsSqlSpatial.
// MsSqlSpatial is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// MsSqlSpatial is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public License
// along with MsSqlSpatial; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using GeoAPI.Geometries;
using MsSqlSpatial;

public partial class UserDefinedFunctions
{
	/// <summary> 
	/// Returns false if the <c>Geometry</c> not simple.
	/// Subclasses provide their own definition of "simple". If
	/// this <c>Geometry</c> is empty, returns <c>true</c>. 
	/// In general, the SFS specifications of simplicity seem to follow the
	/// following rule:
	///  A Geometry is simple if the only self-intersections are at boundary points.
	/// For all empty <c>Geometry</c>s, <c>IsSimple==true</c>.
	/// </summary>
	/// <returns>    
	/// <c>true</c> if this <c>Geometry</c> has any points of
	/// self-tangency, self-intersection or other anomalous points.
	/// </returns>
	[SqlFunction(IsDeterministic = true)]
	public static SqlBoolean IsSimple(SqlBytes ewkb)
	{
		IGeometry geometry = ConvertGeometry.ToGeometry(ewkb);
		if (geometry != null)
		{
			return new SqlBoolean(geometry.IsSimple);
		}
		return SqlBoolean.Null;
	}
};

